﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows;
using System.Collections;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using nl.tno.ict.multitouch.wpfmultitouch.events;

namespace nl.tno.ict.multitouch.wpfmultitouch.controls
{
    public class ImageAdorner : Adorner
    {
        #region Data

        private double _left = 40.0;
        private double _top = -40.0;
        private double _imageWidth = 32;
        private double _imageHeight = 32;
        private int _count = 0;

        #endregion // Data
        
        #region Constructor        
        
        public ImageAdorner(FrameworkElement adornedElement)
            : base(adornedElement)
        {            
        }
        #endregion // Constructor

        /// <summary>
        /// A common way to implement an adorner's rendering behavior is to override the OnRender
        /// method, which is called by the layout system as part of a rendering pass.
        /// </summary>
        /// <param name="drawingContext">The context to be drawn</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (AdornedElement is MTTextbox) { drawingContext.DrawImage(new BitmapImage(new Uri(XMLSettingsReader.SHOWKEYBOARDIMAGE, UriKind.Relative)), new Rect(_count * _left, _top, _imageWidth, _imageHeight)); _count++; }

            if ((bool)AdornedElement.GetValue(MTProperties.CanBeClickedProperty)) { drawingContext.DrawImage(new BitmapImage(new Uri(XMLSettingsReader.CLICKIMAGE, UriKind.Relative)), new Rect(_count * _left, _top, _imageWidth, _imageHeight)); _count++; }
            if ((bool)AdornedElement.GetValue(MTProperties.CanBeDraggedProperty)) { drawingContext.DrawImage(new BitmapImage(new Uri(XMLSettingsReader.DRAGIMAGE, UriKind.Relative)), new Rect(_count * _left, _top, _imageWidth, _imageHeight)); _count++; }
            if ((bool)AdornedElement.GetValue(MTProperties.CanBeRotatedProperty)) { drawingContext.DrawImage(new BitmapImage(new Uri(XMLSettingsReader.ROTATEIMAGE, UriKind.Relative)), new Rect(_count * _left, _top, _imageWidth, _imageHeight)); _count++; }
            if ((bool)AdornedElement.GetValue(MTProperties.CanBeScaledProperty)) { drawingContext.DrawImage(new BitmapImage(new Uri(XMLSettingsReader.SCALEIMAGE, UriKind.Relative)), new Rect(_count * _left, _top, _imageWidth, _imageHeight)); _count++; }
            _count = 0;
        }
    }
}
